package common.webresult;


import java.util.Properties;

/**
 * @description 网络接口的统一返回类
 * @author 帆哥续写辉煌
 * @finish-time 2022-2-20
 */

public class WebResult<T> {

    /**
     *状态返回码
     */
    private int code;
    /**
     * 返回数据
     */
    private T data;
    /**
     * 返回信息
     */
    private String message;

    private WebResult(int code,T data,String message){
        this.code = code;
        this.data= data;
        this.message = message;
    }

    /**
     * 不带返回数据的webResult
     * @return
     */
    public static WebResult okWebResult(){
        //Properties properties = PropertiesCreator.getPropertiesInstance();
       // String message = properties.getProperty(Integer.toString(0));
        //String message ="test";
        return new WebResult(0,null,"成功");
    }
    /**
     * 带返回数据的webResult
     * @return
     */
    public static WebResult<Object> okWebResult(Object data){
        //Properties properties = PropertiesCreator.getPropertiesInstance();
        //String message = properties.getProperty(Integer.toString(0));
        return new WebResult<>(0,data, "成功");
    }
    /**
     * 操作失败的webResult
     * @return
     */
    public static WebResult failWebResult(int code){
        //Properties properties = PropertiesCreator.getPropertiesInstance();
        //String message = properties.getProperty(Integer.toString(code));
        return new WebResult(code,null, "失败");
    }

    /**get and set methods**/
    public int getCode(){
        return this.code;
    }

    public T getData(){
        return this.data;
    }

    public String getMessage() {
        return message;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public void setData(T data) {
        this.data = data;
    }

    public void setMessage(String message) {
        this.message = message;
    }
}
